import React, {Component} from 'react';

function WrapComponent(Com) {
    return class extends Component {
        state = {
            name: 'Hoc'
        };

        getCode (){
            console.log('getCode')
        }

        render() {
            console.log('inner', this.props);
            return <Com getCode={this.getCode} state={this.state} {...this.props} />
        }
    }
}


class Demo extends Component{
    constructor(props) {
        super(props);
        console.log(this.props);
    }
    render() {
        console.log(this.props);
        return (
            <>
                <h4>demo.</h4>
            </>
        )
    }
}

const HOC = WrapComponent(Demo);

export default class index extends Component {
    state = {
        msg: 'msg'
    };
    render() {
        return (
            <>
                <HOC msg={this.state.msg} />
                <h2 onClick={() => {this.setState({msg: new Date()})}}>欢迎使用51实训系统.</h2>
            </>
        )
    }
}
